﻿using System.Text.RegularExpressions;

namespace Gavel.Common.Utilities.Extension;

/// <summary>
/// 正则表达式扩展类
/// </summary>
public static partial class RegexExtension
{
    /// <summary>
    /// IPV4正则表达式
    /// </summary>
    /// <returns>IPV4正则</returns>
    [GeneratedRegex(@"^((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}$")]
    public static partial Regex Ipv4Regex();
    
    /// <summary>
    /// 字符串是否为IPV4地址
    /// </summary>
    /// <param name="host">主机地址</param>
    /// <returns>字符串是否为IPV4地址</returns>
    public static bool IsIpv4(this string host) => Ipv4Regex().IsMatch(host);
}